import request from '@/utils/request';
import qs from 'qs';

// (获取用户的所有评论，后端接口不变)
export function getUserReviews(params) {
    return request({
        url: '/api/user/reviews.do',
        method: 'get',
        params
    });
}

/**
 * 更新或发布评论 (调用万能的submit接口)
 * @param {object} data - 必须包含 { orderId, rating, content }
 */
export const updateReview = (data) => {
    // 你的后端需要 orderId, rating, content
    const formData = qs.stringify(data);
    return request.post('/api/user/review/submit.do', formData, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
};

/**
 * 撤回一条已发布的评论
 * @param {object} data - 必须包含 { reviewId }
 */
export const withdrawReview = (data) => {
    const formData = qs.stringify(data);
    // withdraw.do 接口只需要 reviewId
    return request.post('/api/user/review/withdraw.do', formData, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
};